﻿using Device.API.Applcation.Command.UnitCommand;
using Device.Infrstructre.Interface;
using MediatR;

namespace Device.API.Applcation.CommandHandlers.UnitCommandHandlers
{
    /// <summary>
    /// 批量删除单位信息
    /// </summary>
    public class DelAllCommandHandlers:IRequestHandler<DelAllCommand,int>
    {
        private readonly IUnitRepository _unitRep;
        public DelAllCommandHandlers(IUnitRepository _unitRep)
        {
            this._unitRep = _unitRep;
        }

        public async Task<int> Handle(DelAllCommand request, CancellationToken cancellationToken)
        {
            foreach (var item in request.UnitId)
            {
                var list = await _unitRep.GetModelAsync(item);
                list.IsDel = true;
                list.DelName = request.DelName;//删除人姓名
                list.DelTime = request.DelTime;//删除人时间
                await _unitRep.UpdateAsync(list);
            }
            return 1;
        }
    }
}
